package com.accompany.fragment.my.activity;

import android.view.View;
import android.widget.RadioGroup;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import com.accompany.R;
import com.accompany.adapter.TrainingCenterAdapter;
import com.accompany.base.BaseActivity;
import com.accompany.fragment.my.fragment.TrainingCenterOfflineFragment;
import com.accompany.fragment.my.fragment.TrainingCenterOnlineFragment;
import java.util.ArrayList;
import butterknife.BindView;
import butterknife.OnClick;
import cn.ycbjie.ycstatusbarlib.bar.YCAppBar;

/**
 * 信息说明: 培训中心
 * company: 兰州丰荣信息科技有限公司
 * 创建时间: on 2022/3/17 14 ：59
 * 项目名称：yuanban
 */
public class TrainingCenterActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener, ViewPager.OnPageChangeListener {
    @BindView(R.id.base_title)
    TextView mTitleMsg;
    @BindView(R.id.viewpager_center)
    ViewPager mViewPager;
    @BindView(R.id.rag_center)
    RadioGroup mRadgroup;
    private ArrayList<Fragment> mList = new ArrayList<>();
    @Override
    public int getLayoutId() {
        return R.layout.activity_training_center;
    }
    @Override
    public void initLayoutView() {
        YCAppBar.setStatusBarColor(TrainingCenterActivity.this,
                ContextCompat.getColor(TrainingCenterActivity.this,
                        R.color.base_color));
        mTitleMsg.setText("培训中心");
        initfragment();
        initView();
    }
    @OnClick(R.id.base_back)
    public void OnClick(View view){
        switch (view.getId()){
            case R.id.base_back:
                finishWitchAnimation();
                break;
        }
    }
    private void initView() {
        mViewPager.setCurrentItem(0);
        mRadgroup.check(R.id.rad_shang);
        mRadgroup.setOnCheckedChangeListener(this);
        mViewPager.setOnPageChangeListener(this);
        mViewPager.setAdapter(new TrainingCenterAdapter(getSupportFragmentManager(), mList));
    }
    private void initfragment() {
        TrainingCenterOnlineFragment onlineFragment = new TrainingCenterOnlineFragment();
        mList.add(onlineFragment);
        TrainingCenterOfflineFragment offlineFragment = new TrainingCenterOfflineFragment();
        mList.add(offlineFragment);
    }
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.rad_shang:
                mViewPager.setCurrentItem(0, false);
                break;
            case R.id.rad_xia:
                mViewPager.setCurrentItem(1, false);
                break;
            default:
                break;
        }
    }
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }
    @Override
    public void onPageSelected(int position) {
        switch (position) {
            case 0:
                mRadgroup.check(R.id.rad_shang);
                break;
            case 1:
                mRadgroup.check(R.id.rad_xia);
                break;
            default:
                break;
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
